﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Business.FlowOperation;
using WF_Business;
using WF_DataAccess;

namespace Business.Map
{
    public class MapBLL
    {
        /// <summary>
        /// 获取标注信息
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMarkInfo(string flag)
        {
            var ida = SysParams.OAConnection();
            var dtTemp = new DataTable();
            var sb = new StringBuilder();
            sb.Append("select bdcid, bdcname, xmiid, markattr, datatype, purpose from tb_markinfo where 1=1 ");
            switch (flag)
            {
                case "1":
                    sb.Append(" and datatype in ('征地拆迁红线')");
                    break;
                case "2":
                    sb.Append(" and datatype in ('不动产(房屋)','不动产(土地)')");
                    break;
            }
            ida.RunSql(sb.ToString(), out dtTemp);
            return dtTemp;
        }
        /// <summary>
        /// 获取标注坐标
        /// </summary>
        /// <param name="bdcid"></param>
        /// <returns></returns>
        public static DataTable GetMarkLocation(string bdcid)
        {
            var ida = SysParams.OAConnection();
            var dtTemp = new DataTable();
            var strSql = string.Format("select t.bdcid,t.x,t.y from tb_marklocation t where bdcid='{0}' order by t.bzid", bdcid);
            ida.RunSql(strSql, out dtTemp);
            return dtTemp;
        }
        /// <summary>
        /// 根据数据类型获得对应的表单ID
        /// </summary>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public static string GetFormId(string dataType)
        {
            var strSql = string.Format("SELECT FID FROM ST_FORM WHERE FNAME IN(select text from tb_sjzd  where typecode='TYPETOFORM' and value='{0}') AND ROT='0'", dataType);
            return SysParams.OAConnection().GetValue(strSql);
        }

        /// <summary>
        /// 新增标记信息
        /// </summary>
        /// <param name="ida"></param>
        /// <param name="bdcid"></param>
        /// <param name="name"></param>
        /// <param name="xmiid"></param>
        /// <param name="markAttr"></param>
        /// <param name="dataType"></param>
        /// <param name="purpose"></param>
        public static void InsertTbMarkInfo(IDataAccess ida, string bdcid, string name, string xmiid, string markAttr, string dataType, string purpose)
        {
            var strSql = string.Format(@"insert into tb_markinfo (bdcid, bdcname, xmiid, markattr, dataType, purpose) values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", bdcid, name, xmiid, markAttr, dataType, purpose);
            ida.RunSql(strSql);
        }
        /// <summary>
        /// 新增标记位置信息
        /// </summary>
        /// <param name="ida"></param>
        /// <param name="bdcid"></param>
        /// <param name="pointX"></param>
        /// <param name="pointY"></param>
        public static void InsertTbMarkLocation(IDataAccess ida, string bdcid, string pointX, string pointY)
        {
            var strSql = string.Format(@"insert into tb_marklocation (bzid,bdcid, x, y) values (seq_bzid.nextval,'{0}', '{1}', '{2}')", bdcid, pointX, pointY);
            ida.RunSql(strSql);
        }

        /// <summary>
        /// 删除标记信息
        /// </summary>
        /// <param name="bdcId"></param>
        /// <returns></returns>
        public static string Delete(string bdcId)
        {
            var ida = SysParams.OAConnection(true);
            try
            {
                var strSql = string.Format(" delete from tb_marklocation where bdcid='{0}'", bdcId);
                ida.RunSql(strSql);
                strSql = string.Format(" delete from tb_markinfo where bdcid='{0}'", bdcId);
                ida.RunSql(strSql);
                ida.Close(true);
                return "删除成功";
            }
            catch (Exception ex)
            {
                ida.Close(false);
                return "删除失败" + ex.Message;
            }
        }
        /// <summary>
        /// 获取不动产房屋数据
        /// </summary>
        /// <returns></returns>
        public static DataTable GetEstateHouse()
        {
            var dtTemp = new DataTable();
            var strSql = " select id, iid, input_index, ssxm, zfsj, mj, sheng, zl, sfjf, sfcc, yxj, sfqdxy, gsmj, bcxyje, tdyt, shi, qu, ccsj, jfsj, qdxysj, sfzfwc, bdclx from ut_gzzdcq_bdcxx_bcqfwxx order by iid desc";
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }
        /// <summary>
        /// 根据ID获取覆盖物坐标
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DataTable GetOverlayPoint(string id)
        {
            var dtTemp = new DataTable();
            var strSql = string.Format("select x , y from tb_marklocation t where bdcid='{0}'", id);
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }
        /// <summary>
        /// 根据ID获取覆盖物属性
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DataTable GetOverlayMarkInfo(string id)
        {
            var dtTemp = new DataTable();
            var strSql = string.Format("select markattr from tb_markinfo t where bdcid='{0}' ", id);
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }
        /// <summary>
        /// 根据iid获取mapid
        /// </summary>
        /// <param name="iid"></param>
        /// <returns></returns>
        public static string GetMapidByIID(string iid)
        {
            var strSql = string.Format("select bdcid from tb_markinfo t where xmiid='{0}' and rownum<=1 ", iid);
            return SysParams.OAConnection().GetValue(strSql);
        }
    }
}
